from rest_framework import serializers

from company.models import Job
from company.serializers import CompanySerializer
from userinfo.models import Company


class JobListSerializer(serializers.ModelSerializer):

    company = serializers.SerializerMethodField()
    city=serializers.SerializerMethodField()
    class Meta:
        model = Job
        fields = '__all__'

    def get_company(self, obj):
        company = Company.objects.get(pk=obj.pk)
        return CompanySerializer(company).data

    def get_city(self, obj):
        company = Company.objects.get(pk=obj.pk)
        return CompanySerializer(company).data.get('name')